/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Unless required by applicable law or
 * agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.rhok.ncn.common;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import org.rhok.ncn.datatypes.LocationData;
import org.rhok.ncn.storage.NCNDatabaseManager;

import android.content.Context;
import android.os.Handler;
import android.telephony.TelephonyManager;

/**
 * Stores the state and all information or references that are used throughout the application.
 * @author pfritzsche
 */
public class CommonData {
    public static boolean isActivityRunning = false;
    public static int signalStrength;
    public static int wifiStrength;
    
	private static final BlockingQueue<LocationData> locs = new LinkedBlockingQueue<LocationData>();
	private static NCNDatabaseManager db;
	private static Handler handler;
	private static String provider;
	
    public static BlockingQueue<LocationData> locs() { return locs; }
	public static Handler handler() { return handler; }
	public static NCNDatabaseManager db() { return db; }
	public static String provider() { return provider; }
	
    public synchronized static void setFields(final Context context, Handler handler) {
        if (db == null) {
            db = new NCNDatabaseManager(context);
        }
        
        CommonData.handler = handler;
        provider = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)
                ).getNetworkOperatorName();
    }
}
